package com.sims.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.sims.bean.Student;
import com.sims.bean.StudentPosition;
import com.sims.beanEnhanced.StudentStudentPosition;
import com.sims.dao.IStudentDAO;
import com.sims.dao.IStudentPositionDAO;
import com.sims.util.Constant;
import com.sims.util.HttpSessionUtil;

public class StudentPositionService {
	@Autowired
	private IStudentDAO studentDAO;
	@Autowired
	private IStudentPositionDAO studentPositionDAO;
	
	
	/** 学生、老师均可调用。找出班级内所有学生职务。传入Tclass.cid。参数返回List。
	 * @param Tclass
	 * @param studentPositionList
	 * @return
	 */
	public Map<String, String> findClassStudentPosition(List<StudentStudentPosition> studentPositionList) {
		Map<String, String> result = new HashMap<String, String>();

		@SuppressWarnings("unchecked")
		List<StudentStudentPosition> temp = studentPositionDAO.findStudentStudentPositionByCid(HttpSessionUtil.getUserClassId());
		
		for (StudentStudentPosition studentPosition : temp) {
			studentPositionList.add(studentPosition);
		}
		result.put(Constant.SUCCESS, null);
		return result;
	}

	public Map<String, String> modifyStudentPosition(
			Student student, StudentPosition studentPosition) {
		Map<String, String> result = new HashMap<String, String>();
		Student s = studentDAO.findById(student.getSid());
		if (s==null) {
			result.put(Constant.ERROR, "Student Not Exists");
			return result;
		}
		StudentPosition spInDB = (StudentPosition) studentPositionDAO.findBySno(student.getSno()).get(0);
		spInDB.setPosition(studentPosition.getPosition());
		studentPositionDAO.attachDirty(spInDB);
		result.put(Constant.SUCCESS, null);
		return result;
	}
}
